package com.twu.biblioteca;

/**
 * Created by sravanns on 19/06/14.
 */
public class ReturnMovie implements MenuAction {
    private Library library;

    private UserInterface UIApplication;


    public ReturnMovie(Library obj, UserInterface ui) {
        library = obj;
        UIApplication =ui;
    }
    @Override
    public String toString() {
        return "Return Movie";
    }

    @Override
    public Result performAction(String user) {
        UIApplication.display("Enter Movie Name");
        String input = UIApplication.acceptTitle();
        Movie movie = library.getMovieFromList(input);
        Result result=new Result();
        if (movie != null) {
            if (library.returnMovie(movie,user)) {
                result.setResult("Thank you for returning the movie.",true);

            } else
                result.setResult("That is not a valid movie to return.",false);



        }
        else
            result.setResult("That movie is not valid book in Library. please consider checking the spelling",true);

        return result;
    }
}

